/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ejercicio.practica10;

import java.io.File;

/**
 *
 * @author manolo
 */
public class UsaRWFileMonitorAN extends Thread {

    private RWMonitorAN m;
    private int tipo;

    public UsaRWFileMonitorAN(RWMonitorAN m, int tipo) {
        this.m = m;
        this.tipo = tipo;
    }

    @Override
    public void run() {
        if (tipo == 0) {
            m.comienzaEscritura();
            m.finalizaEscritura();
        } else {
            m.comienzaLectura();
            m.finalizaLectura();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        RWMonitorAN m = new RWMonitorAN(new File("Datos.dat"));
        UsaRWFileMonitorAN[] hilos = new UsaRWFileMonitorAN[10];

        for (int i = 0; i < hilos.length; i++) {
            hilos[i] = new UsaRWFileMonitorAN(m, i);
        }
        for (int i = 0; i < hilos.length; i++) {
            hilos[i].start();
        }
        for (int i = 0; i < hilos.length; i++) {
            hilos[i].join();
        }
    }
}
